<#include "/layout/header.ftl" />
<#import "/include/ui.ftl" as blue />

<script src="${rc_path}/js/jquery/jquery-treetable.js"></script>
<script>

$(function()
{
	$("#tbl_tree").treetable({expandable : true, expanderTemplate : "<a>&nbsp;</a>"});
	
});

function search_click()
{
	var obj = $.getObject("#div_search");	
	$("#div_grid").simpleLoad("/auth/menu_list", obj, 1);
	
}

function app_change()
{
	var appId = $("#slt_app_id").val();
	window.location = "${path}/auth/menu_list?appId=" + appId;
}

function delete_click(id)
{
	var obj = {id: id};
	$.simpleConfirm("确定删除？", function(ops)
	{
		$.simpleAjax("/auth/menu_delete", obj, function(o)
		{
			$.successAlert("删除成功");
			$("#tr_" + id).remove();
		});
	});
}


</script>

<div class="am-g am-cf am-margin-top am-margin-bottom">
	<div class="am-u-sm-3 am-padding-right-0">
		<div class="am-btn-group">
			<a href="${path}/auth/menu_get" class="am-btn am-btn-primary am-radius">添加</a>
			<a href="javascript:void(0)" onclick="blue_refresh_click('/auth/menu_refresh')" class="am-btn am-btn-default am-radius">刷新缓存</a>
		</div>
	</div>
	<div class="am-u-sm-9 am-form-inline" id="div_search">
		<select id="slt_app_id" name="appId" data-am-selected="{'btnWidth': '200px'}" onchange="app_change()">
			<@blue.select list=appList value=(app.id)!"0" />
		</select>
	</div>
</div>

<div class="am-g" id="div_grid">
	<div class="am-u-sm-12">
		<table class="am-table am-table-striped am-table-hover" id="tbl_tree">
			<thead>
			<tr>
				<th width="300">名称</th>
				<th>链接</th>
				<th width="100">排序</th>
				<th width="100">权限个数</th>
				<th width="100">状态</th>
				<th width="300">操作</th>
			</tr>
			</thead>
			<tbody>
			<#if treeList?? && treeList?size &gt; 0>
			<@tree map=treeList key="0" />
			</#if>
			</tbody>
		</table>
	</div>
</div>

<#macro tree map key count=0>
	<#assign voList=map[key]! />
	
	<#if voList??>
	<#list voList as vo>
			<tr id="tr_${vo.id}" data-tt-id="${vo.id}" data-tt-parent-id="${vo.parentId!}">
				<td title="${vo.name!}">${vo.name!}</td>
				<td title="${vo.url!}">${vo.url!}</td>
				<td>${vo.sort!}</td>
				<td <#if vo.auths == 0>style="color: red;"</#if>>${vo.auths!}</td>
				<td>${vo.state!}</td>
				<td>
					<div class="am-btn-group">
						<a href="${path}/auth/menu_get?id=${vo.id}" class="am-btn am-btn-primary am-btn-sm am-radius">编辑</a>
						<a href="${path}/auth/menu_get?parentId=${vo.id}" class="am-btn am-btn-danger am-btn-sm am-radius">子菜单</a>
						<a href="javascript:void(0)" onclick="delete_click('${vo.id!}')" class="am-btn am-btn-danger am-btn-sm am-radius">删除</a>
						<#if count &gt; 0>
						<a href="${path}/auth/menu_auth_list?menuId=${vo.id}" class="am-btn am-btn-default am-btn-sm am-radius">权限</a>
						</#if>
					</div>
				</td>
			</tr>
			<@tree map=map key=vo.id?string count=count+1 />
	</#list>
	</#if>
	
</#macro>

<#include "/layout/footer.ftl" />